repo: Initialize GPGME in instance init()
authorMatthew Barnes <mbarnes@redhat.com>
Thu, 30 Apr 2015 15:06:24 +0000 (11:06 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Fri, 1 May 2015 18:38:17 +0000 (14:38 -0400)
Initially I had this in class_init() but there it would get invoked
during introspection scanning.

src/libostree/ostree-repo.c

index 262d0e9d988624ac7143da822b4ff3fa645d08a5..5bdba3c659e20faff242ab51a0df4be4a2db362e 100644 (file)
@@ -507,6 +507,15 @@ ostree_repo_class_init (OstreeRepoClass *klass)
 static void
 ostree_repo_init (OstreeRepo *self)
 {
+  static gsize gpgme_initialized;
+
+  if (g_once_init_enter (&gpgme_initialized))
+    {
+      gpgme_check_version (NULL);
+      gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
+      g_once_init_leave (&gpgme_initialized, 1);
+    }
+
   g_mutex_init (&self->cache_lock);
   g_mutex_init (&self->txn_stats_lock);
 
@@ -3056,9 +3065,6 @@ sign_data (OstreeRepo     *self,
                                cancellable, error))
     goto out;
 
-  gpgme_check_version (NULL);
-  gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
-  
   if ((err = gpgme_new (&context)) != GPG_ERR_NO_ERROR)
     {
       ot_gpgme_error_to_gio_error (err, error);